<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"[]>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xml:lang="en">
<META http-equiv="Content-Type" content="text/html; CHARSET=UTF-8">
<?php
  require_once 'header.php';
  session_start();
  ob_start();

  $ConnectDB = new connectDB();
  $SQLList = new sqlList();

  $idPoem = "";
  if(isset($_POST["sid"]))
  {
    $idPoem = $_POST["sid"];
  }
  else
  {
    if(isset($_GET["sid"]))
    {
      $idPoem = $_GET["sid"];
    }
  }
  $idPoem2 = $idPoem;

  /* Song informaton */
  $result = $ConnectDB->buildPreparedStatments($SQLList->SelectSongDetail);
  $result->bind_param( 'i', $idPoem );
  $result->execute();
  $result->bind_result( $title, $content, $music, $lyrics, $youtubeCode, $album);
  $resultCnt = $result->fetch();
  $result->close();
  $pattern = '/\n/i';
  $replacement = '<br/>';
  $name = $title;
  $contentOrgi = $content;
  $content = preg_replace($pattern, $replacement, $content);
  /* Song informaton [End] */

  /* Categroy Information */
  $resultCat = $ConnectDB->buildPreparedStatments($SQLList->SelectSongCategory);
  $resultCat->bind_param( 'i', $idPoem );
  $resultCat->execute();
  $resultCat->bind_result($categoryId, $categoryName);
  $index = 0;

  while ($rowSet = $resultCat->fetch())
	{
	  $categoryIdArr[$index] = $categoryId;
	  $categoryArr[$index] = $categoryName;
	  $index++;
	}
	$resultCat->close();

	/* Categroy Information */
	$resultCat = $ConnectDB->buildPreparedStatments($SQLList->SelectSongCategory);
	$resultCat->bind_param( 'i', $idPoem );
	$resultCat->execute();
	$resultCat->bind_result($categoryId, $categoryName);
	$index = 0;
  $categoryList = "";
	while ($rowSet = $resultCat->fetch())
	{
	  $categoryIdArr[$index] = $categoryId;
	  $categoryArr[$index] = $categoryName;
	  $categoryList = $categoryList . $categoryName . ",";
	  $index++;
	}
	$resultCat->close();

	/* Song informaton [End] */
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>詩歌-主頁</title>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<!--[if IE 6]><link rel="stylesheet" href="style.ie6.css" type="text/css" media="screen" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" href="style.ie7.css" type="text/css" media="screen" /><![endif]-->
<script type="text/javascript" src="script.js"></script>
<style type="text/css">
.art-post .layout-item-0 {
	margin-top: 13px;
	margin-bottom: 13px;
}

.art-post .layout-item-1 {
	color: #242424;
	background: url(images/e4edc.png) top left no-repeat #FFFFFF;
	padding: 0px;
}

.art-post .layout-item-2 {
	padding: 10px;
}

.ie7 .art-post .art-layout-cell {
	border: none !important;
	padding: 0 !important;
}

.ie6 .art-post .art-layout-cell {
	border: none !important;
	padding: 0 !important;
}
</style>
<script>
  	var songListName = [<?php require_once 'songlistName_json.php';?>];
  	var songListId = [<?php require_once 'songlistId_json.php';?>];
    $(document).ready(function()
    {
      $("input#autocomplete").autocomplete({
      	source: songListName
      });
    });

		function checkSongId()
		{
			for (var i=0; i< songListName.length; i++)
			{
				if(document.getElementById("autocomplete").value == songListName[i])
				{
  				document.getElementById("sid").value = songListId[i];
  			}
			}
		}
		function songEdit()
		{
			document.getElementById("songForm").submit();
		}
  </script>
</head>
<body>
<div id="art-main">
		<div class="cleared reset-box"></div>
		<div class="art-header">
			<div class="art-header-position">
				<div class="art-header-wrapper">
					<div class="cleared reset-box"></div>
					<div class="art-header-inner">
						<div class="art-headerobject">耶 和 華 是 我 的 力 量 、 是 我 的 盾 牌 ． 我 心 裡 倚 靠 他 、 就 得 幫 助 ． 所 以 我 心 中 歡 樂 ． 我 必 用 詩 歌 頌 讚 他 。(詩 28:7)</div>
						<div class="art-logo">
							<h1 class="art-logo-name">
							</h1>
							<h2 class="art-logo-text">詩 歌 庫</h2>
								<div class="search-region">
                  <form action="/poem/song.php" method="get" onsubmit="checkSongId();">
                    <input type="hidden" id="sid" name="sid"/>
                    <input id="autocomplete" size="20" name="query" style="color: rgb(0, 0, 0);" />
                    <input id="searchIcon" type="submit" title="搜尋" value="搜尋" />
                  </form>
               </div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="cleared reset-box"></div>
		<div class="art-bar art-nav">
			<div class="art-nav-outer">
				<div class="art-nav-wrapper">
					<div class="art-nav-inner">
						<ul class="art-hmenu">
							<li><a href="index.php">主頁</a></li>
							<li><a href="categorylist.php" class="active">詩歌分類</a></li>
							<li><a href="albumlist.php">詩歌專輯</a></li>
							<li><a href="advancedsearch.php">進階搜尋</a></li>
							<li><a href="contactus.php">聯絡我們</a></li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		<div class="cleared reset-box"></div>
		<div class="art-box art-sheet">
			<div class="art-box-body art-sheet-body">
				<div class="art-layout-wrapper">
					<div class="art-content-layout">
						<div class="art-content-layout-row">
              <div class="youtubeContain">
              	<?php
              	  if ($youtubeCode != "")
              	  {
              	?>
                <iframe width="500px" height="350px" src="http://www.youtube.com/embed/<?php print $youtubeCode;?>" frameborder="0" allowfullscreen>
                </iframe>
                <?php
              	  }
              	  else
              	  {
              	?>
              	<img src="/poem/images/music-icon-2.png" width="200px"  style="float: right; margin: 30px 150px 0px 0px;"></img>
              	<?php
              	  }
                ?>
              </div>
              <div class="infoContain">
              	<?php
              	  if (isset($_SESSION["userid"]))
                  {
                    print '<a href="javascript:songEdit();">[ 編輯 ]</a>';
                  	print '<form id="songForm" name="songForm" action="/poem/admin/songEdit.php" method="post">';
                  	print '<input type="hidden" name="sid" id="sid" value="' . $idPoem2 . '"/>';
                  	print '<input type="hidden" name="title" id="title" value="'. $name . '"/>';
                  	print '<input type="hidden" name="album" id="album" value="' . $album . '" />';
                  	print '<input type="hidden" name="music" id="music" value="' .  $music . '"/>';
                  	print '<input type="hidden" name="lyrics" id="lyrics" value="' . $lyrics . '" />';
                  	print '<input type="hidden" name="content" id="content" value="' . $contentOrgi . '" />';
                  	print '<input type="hidden" name="youtubeCode" id="youtubeCode" value="' . $youtubeCode . '" />';
                  	print '<input type="hidden" name="category" id="category" value="' . $categoryList . '" />';
                  	print '</form>';
                  }
              	print "<div>分類：";
              	if(count($categoryArr)>0)
              	{
                	for ($i=0; $i < count($categoryArr); $i++)
                	{
                	  print '<a href="category.php?cid=' . $categoryIdArr[$i] . '&ctitle=' . $categoryArr[$i] . '">';
                    print "$categoryArr[$i]";
                    print '</a>, ';
                  }
              	}
              	else
              	{
                  print "未有分類";
              	}
                print "</div>\n";

                if ($resultCnt > 0 )
              	{
              	   print "<div>歌名: $name</div>\n";
              	   print "<div>專輯 : $album</div><br/>\n";
              	   print "<div>作曲: $music</div>\n";
              	   print "<div>作詞 : $lyrics</div><br/>\n";
              	   print "<div>歌詞: <br/>$content</div>\n";
              	   //print "<div>YoutubeCode: $youtubeCode</div>\n";
              	}
              	?>
              </div>
							<div><a href="javascript:alert('建設中')">加入我的詩歌清單</a></div>
						</div>
      		</div>
      	</div>
      </div>
    </div>
		<div class="cleared"></div>
		<?php require_once 'footer.php';?>
	</div>
</body>
</html>